package flc.ast.fragment;

import static com.stark.imgocr.api.VerifyMethod.APPCODE;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.ClipboardUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.Utils;
import com.stark.imgocr.ImgOcrEntry;
import com.stark.imgocr.api.Config;
import com.stark.imgocr.api.IRetCallback;
import com.stark.imgocr.api.bean.OcrRetBean;
import com.stark.picselect.PhotoSelectorBuilder;
import com.stark.picselect.config.PhotoConfig;
import com.stark.picselect.entity.SelectMediaEntity;
import com.stark.picselect.interfaces.OnSelectResultListener;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import flc.ast.R;
import flc.ast.activity.MyAlbumActivity;
import flc.ast.activity.PatternTextActivity;
import flc.ast.activity.PhotoRecActivity;
import flc.ast.activity.RecResultActivity;
import flc.ast.databinding.FragmentTextBinding;
import io.reactivex.rxjava3.core.ObservableEmitter;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.device.WallpaperUtil;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.IntentUtil;
import stark.common.basic.utils.RxUtil;
import stark.common.basic.utils.StkPermissionHelper;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link TextFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class TextFragment extends BaseNoModelFragment<FragmentTextBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_text;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.ivCopy.setOnClickListener(this);
        mDataBinding.ivShare.setOnClickListener(this);
        mDataBinding.ivPhotoRec.setOnClickListener(this);
        mDataBinding.ivPictureRec.setOnClickListener(this);
        mDataBinding.ivPatternText.setOnClickListener(this);
        mDataBinding.ivPictureMagnify.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivCopy://复制
                ClipboardUtils.copyText(mDataBinding.tvDailyText.getText().toString());
                ToastUtils.showShort(getString(R.string.copy_success_tips));
                break;
            case R.id.ivShare://分享
                IntentUtil.shareText(mContext, mDataBinding.tvDailyText.getText().toString());
                break;
            case R.id.ivPhotoRec://拍照识别
                startActivity(PhotoRecActivity.class);
                break;
            case R.id.ivPictureRec://图片识别
                MyAlbumActivity.type = 0;
                startActivity(MyAlbumActivity.class);
                break;
            case R.id.ivPatternText://花样文字
                startActivity(PatternTextActivity.class);
                break;
            case R.id.ivPictureMagnify://图片放大
                MyAlbumActivity.type = 1;
                startActivity(MyAlbumActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        String[] data = getResources().getStringArray(R.array.daily_data);
        Random random = new Random();
        mDataBinding.tvDailyText.setText(data[random.nextInt(10)]);
    }

//    private void getPermission() {
//        StkPermissionHelper.permission(StkPermissionHelper.Permission.ACCESS_IMAGE_VIDEO)
//                .reqPermissionDesc(getString(R.string.get_storage_permission))
//                .callback(new StkPermissionHelper.ACallback() {
//                    @Override
//                    public void onGranted() {
//                        goToRec();
//                    }
//                }).request();
//    }

//    private void goToRec() {
//        PhotoSelectorBuilder.builder(getActivity())
//                .mode(PhotoConfig.Mode.PHOTO)
//                .minCount(1)
//                .maxCount(1)
//                .listener(new OnSelectResultListener<List<SelectMediaEntity>>() {
//                    @Override
//                    public void onResult(List<SelectMediaEntity> data) {
//                        try {
//                            Bitmap bitmap = BitmapFactory.decodeStream(Utils.getApp().getContentResolver().openInputStream(Uri.parse(data.get(0).getUri())));
//                            applyCropImage(bitmap);
//                        } catch (FileNotFoundException e) {
//                            throw new RuntimeException(e);
//                        }
//                    }
//                });
//    }


}